package com.lumlord.common.database.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 *  德鲁伊 数据库 
 * @author GPF
 *
 */
@Component
public class DruidConfig {
	
    public DataSource druidDataSource(String ippd,String username,String password) {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(String.format(URL, ippd));
        datasource.setUsername(username);
        datasource.setPassword(password);
        datasource.setDriverClassName(driverClassName);
        /*datasource.setInitialSize(initialSize);
        datasource.setMinIdle(minIdle);
        datasource.setMaxActive(maxActive);
        datasource.setMaxWait(maxWait);
        datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
        datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
        datasource.setValidationQuery(validationQuery);
        datasource.setTestWhileIdle(testWhileIdle);
        datasource.setTestOnBorrow(testOnBorrow);
        datasource.setTestOnReturn(testOnReturn);*/
        /*try {
        	if(!"null".equals(filters)) {
        		datasource.setFilters(filters);
        	}
        } catch (SQLException e) {
            logger.error("druid configuration initialization filter", e);
        }*/
        return datasource;
    }
    
    private Logger logger = LoggerFactory.getLogger(DruidConfig.class);
    private final String URL = "jdbc:mysql://%s?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false"; 

//    @Value("${spring.datasource.driver-class-name}")
    private String driverClassName = "com.mysql.jdbc.Driver";

   /* @Value("${spring.datasource.initialSize}")
    private int initialSize;

    @Value("${spring.datasource.minIdle}")
    private int minIdle;

    @Value("${spring.datasource.maxActive}")
    private int maxActive;

    @Value("${spring.datasource.maxWait}")
    private int maxWait;

    @Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
    private int timeBetweenEvictionRunsMillis;

    @Value("${spring.datasource.minEvictableIdleTimeMillis}")
    private int minEvictableIdleTimeMillis;

    @Value("${spring.datasource.validationQuery}")
    private String validationQuery;

    @Value("${spring.datasource.testWhileIdle}")
    private boolean testWhileIdle;

    @Value("${spring.datasource.testOnBorrow}")
    private boolean testOnBorrow;

    @Value("${spring.datasource.testOnReturn}")
    private boolean testOnReturn;

    @Value("${spring.datasource.filters:null}")
    private String filters;

    @Value("${spring.datasource.logSlowSql}")
    private String logSlowSql;*/

}
